[译]如何根据Pandas中的列名获取列所在的index位置?

您所在的位置:网站首页 pandas 列名 [译]如何根据Pandas中的列名获取列所在的index位置?

[译]如何根据Pandas中的列名获取列所在的index位置?

#[译]如何根据Pandas中的列名获取列所在的index位置?| 来源: 网络整理| 查看: 265

原文来源:https://stackoverflow.com/questions/13021654/get-column-index-from-column-name-in-python-pandas

可以使用 .get_loc实现。

In [45]: df = DataFrame({"pear": [1,2,3], "apple": [2,3,4], "orange": [3,4,5]}) In [46]: df.columns Out[46]: Index([apple, orange, pear], dtype=object) In [47]: df.columns.get_loc("pear") Out[47]: 2


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3